const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    role:'',
		active:0
  },
	onChange(e) {
		this.setData({
			active: e.detail.index
		});
	},

  /**
   * 生命周期函数--监听页面加载
   */
   onLoad: function (options) {
    this.setData({
      role: app.globalData.userInfo.role,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
   onShow: function () {
    if (typeof this.getTabBar === 'function' && this.getTabBar()) {
      let selected = 1;
      if (this.data.role == 1) {
        selected = 1;
      } else if (this.data.role == 3) {
        selected = 0;
      }
      this.getTabBar().setData({
        selected: selected
      })
    }
		wx.getStorage({
			key: 'activeData',
			success: (res) => {
					let data = 	res.data
					this.setData({
						active: data
					})
					wx.removeStorage({
							key: 'activeData',
					})
			}
	})
		// this.onPullDownRefresh()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
   onPullDownRefresh() {
		if (this.data.active == 0) {
			const planing = this.selectComponent('.planing');
			planing.onPullDownRefresh && planing.onPullDownRefresh()
		} else {
			const had_plan = this.selectComponent('.had_plan');
			had_plan.onPullDownRefresh && had_plan.onPullDownRefresh()

		}
  },
  onReachBottom() {
		if (this.data.active == 0) {
			const planing = this.selectComponent('.planing');
			planing.onReachBottom && planing.onReachBottom()
		} else {
			const had_plan = this.selectComponent('.had_plan');
			had_plan.onReachBottom && had_plan.onReachBottom()
		}
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})